from typing import List

from dao.match_dao import MatchDao
from model.match_model import MatchModel

group_dao = MatchDao()


class MatchService:
    def create(self, model: MatchModel) -> int:
        """
        创建
        """
        result = group_dao.get_by_name(model.name)
        if not result:
            return group_dao.create(model)

    def update(self, model: MatchModel) -> int:
        """
        更新
        """
        if group_dao.get(model.id):
            group_dao.update(model)
        return model.id

    def delete(self, id: int) -> int:
        """
        删除
        """
        if self.get(id):
            return group_dao.delete(id)

    def list(self) -> List[MatchModel]:
        """
        获取全部
        """
        return group_dao.list()

    def get(self, id: int) -> MatchModel:
        """
        获取某个数据
        """
        return group_dao.get(id)

    def get_by_name(self, name) -> MatchModel:
        """
        根据名称获取某个数据
        """
        return group_dao.get_by_name(name=name)